import { parse } from '@iarna/toml';
import * as monaco from 'monaco-editor';

export function getMarkersFromError(error: any): monaco.editor.IMarkerData[] {
  const line = error.line + 1;
  const column = error.col + 1;

  return [
    {
      endColumn: column,
      endLineNumber: line,
      message: error.message,
      severity: monaco.MarkerSeverity.Error,
      startColumn: column,
      startLineNumber: line,
    },
  ];
}
/**
 * toml 转换为 json
 * @param source toml source
 * @returns json string
 */
export function tomlParseToJSON(source: string): string {
  const data = parse(source);
  const json = JSON.stringify(data, null, 2);
  return json;
}
